home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
apps
/
521
/
midipl02
/
midiplay.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-17
|
3KB
|
121 lines
/*
* File: midiplay.c
* SGoldthorpe 9-Apr-91
*/
/*
* midiplay - play standard midi files (sometimes)
* FREEWARE (C) 1991 Stephen Goldthorpe - Take all you want! But please it be
* known if you've made mods. I don't want a lot of complaints about code I've
* never even seen before (life's hard enough without all of that)!
* SGoldthorpe.wgc-e@rx.xerox.com
* goldthor@arisia.xerox.com
*/
/*
* REVISION LOG
* ============
* 0.1 SGoldthorpe 20-Mar-91 Created for Atari ST / Sozobon C. It's
* a bit atari specific in places buy i've
* tried to make it UNIX(tm) looking for
* easier porting (if anyone feels brave
* enough to try.
* 0.2 SGoldthorpe 7-Apr-91 Messed up the code in mf_intp to
* allow type 1 midi files. Timing is
* still a bit hairy but it plays 80%
* of the files I have OK.
*/
#include <stdio.h>
#include <types.h>
#include <stat.h>
#include <fcntl.h>
#include <malloc.h>
#include <errno.h>
/* MACRO DEFS */
#define RELEASE 0
#define VERSION 2
#define DATE " 9-Apr-91"
/* EXTERNAL DECLS */
extern int mf_intp();
/* GLOBAL CONSTANTS */
char app_name[] = "midiplay";
/* FUNCTION DECLS */
static void play();
/* MAIN CODE - SHORT & SWEET */
int main(argc,argv)
int argc;
char *argv[];
{ int file_n;
/* title (so you and I know what's what) */
(void)printf("%s v %d.%d (%s)\n",app_name,RELEASE,VERSION,DATE);
/* check args */
if(argc<2)
{ (void)fprintf(stderr,"%s: <file1> (...<fileN>) \n",app_name);
exit();
};
/* play all files in arg list */
for(file_n=1;file_n<argc;file_n++)
play(argv[file_n]);
};
/* FUNCTION DEFS */
static void play(file)
char *file;
{ struct stat stat_buff;
BYTE *file_buff;
int fd;
unsigned int len;
#ifdef DEBUG
(void)fprintf(stderr,"%s: play %s\n",app_name,file);
#endif
/* open the file (is possible) and get info */
if((fd=open(file,O_RDONLY))<0)
{ (void)fprintf(stderr,"%s: can't open %s\n",app_name,file);
return(-1);
};
if(stat(file,&stat_buff)<0)
{ perror(app_name);
return(-1);
};
len=(unsigned int)stat_buff.st_size;
/* get some workspace... */
#ifdef DEBUG
(void)fprintf(stderr,"%s: malloc (%d)\n",app_name,len);
#endif
if((file_buff=(BYTE*)malloc(len))==NULL)
{ (void)fprintf(stderr,
"%s: couldn't get enough memory for %s (%d bytes)\n",
app_name,file,len);
(void)close(fd);
return(-1);
};
/* ...and fill it */
if(read(fd,(BYTE*)file_buff,len)!=len)
{ (void)fprintf(stderr,"%s: problem reading %s\n",app_name,file);
(void)close(fd);
free((char*)file_buff);
return(-1);
};
(void)close(fd);
/* send it to mf_intp for the hard work */
(void)mf_intp(file_buff,file,len);
/* and tidy up */
free((char*)file_buff);
};
/* THAT'S ALL FOLKS! */